package com.socialuni.center.web.entity;

import com.socialuni.center.web.manage.*;
import com.socialuni.center.web.model.DO.oAuth.ThirdUserDO;
import com.socialuni.center.web.model.DO.oAuth.ThirdUserTokenDO;
import com.socialuni.center.web.model.DO.user.DevAccountDO;
import com.socialuni.center.web.model.EO.ThirdUserLoginEO;
import com.socialuni.sdk.model.DO.user.UserDO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

//授权用户信息
@Service
public class ThirdUserLoginEntity {
    @Resource
    ThirdUserTokenDOCreate thirdUserTokenDOCreate;
    @Resource
    private ThirdUserDOManage thirdUserDOManage;
    @Resource
    private ThirdUserAuthDOCreate thirdUserAuthDOCreate;


    public ThirdUserLoginEO thirdUserLogin(DevAccountDO threeDevDO, UserDO userDO, String oAuthType) {
        //只是记录一个授权记录
        ThirdUserDO threeUserDO = thirdUserDOManage.getOrCreate(threeDevDO.getId(), userDO.getId());

        thirdUserAuthDOCreate.getOrCreate(threeUserDO, oAuthType);
        //授权成功
        //token有效期三个月
        //生成userToken
        ThirdUserTokenDO tokenDO = thirdUserTokenDOCreate.create(userDO.getId(), threeDevDO.getId());
        return new ThirdUserLoginEO(threeUserDO, tokenDO);
    }
}
